package com.itlong.cloud.rabbitmq.consumer;

import com.itlong.cloud.property.service.IPropertyEquipService;
import com.itlong.cloud.rabbitmq.config.MessageSender;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <desc>
 *      物业接收APP用户地址，查询地址中的设备消费者
 * </desc>
 *
 * @createDate 2017/10/23
 */
@Component
public class EquipAddrChangeConsumer {

    private static final Logger LOG = LoggerFactory.getLogger(EquipAddrChangeConsumer.class);

    //物业设备服务层
    @Autowired
    IPropertyEquipService iPropertyEquipService;

    //消息队列
    @Autowired
    private MessageSender messageSender;


    /**
     * <desc>
     *      物业接收APP用户地址，查询地址中的设备消费者
     * <desc/>
     * @param   message 消息数据
     * @author Biao.R
     * @createDate 2017/10/23
     */
    /*@RabbitListener(queues = RabbitMQConstant.RABBITMQ_EQUIP_ADDR_CHANGE_QUEUE)
    public void process(Message message, Channel channel) throws IOException {
        byte[] body = message.getBody();
        LOG.info("RabbitMQ_接收设备地址变更后受影响用户的地址，查询设备信息消费端:" + body);
        try {
            List<UserDeviceAuthAddreddDTO> userDeviceAuthAddreddDTOS = JSON.parseObject(new String(body), new TypeReference<List<UserDeviceAuthAddreddDTO>>() {
            });
            if (userDeviceAuthAddreddDTOS != null && !userDeviceAuthAddreddDTOS.isEmpty()) {
                iPropertyEquipService.sendEquipByAddress(userDeviceAuthAddreddDTOS, DeviceAuthEnum.DEVICEAUTH_PROPERTY.getType());
            }

        } catch (Exception e) {
            channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
            LOG.error("【RabbitMQ_接收用户地址查询设备信息消费端】:处理异常", e);
        }finally {
            //手动确认消息消费成功。
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }
    }*/
}